Back


Goal 17: Partnerships for the goals

Public finances


GS Public finances
# Import 
indtagter_raw <-
  statgl_url("OFXREAI", lang = language) %>% 
  statgl_fetch(
    "sector"      = px_all(),
    "transaction" = 43,
    "time"        = px_all(),
    .col_code     = TRUE) %>% 
  as_tibble()

udgifter_raw <-
  statgl_url("OFXREAU", lang = language) %>% 
  statgl_fetch(
    "sector"      = px_all(),
    "transaction" = 44,
    "time"        = px_all(),
    .col_code     = TRUE) %>% 
  as_tibble()

indtagter <- 
  indtagter_raw %>% 
  mutate(transaction = transaction %>% str_remove_all("[:digit:]|[:punct:]|\\+") %>% trimws()) %>% 
  spread(2, 4)

udgifter <- 
  udgifter_raw %>% 
  mutate(transaction = transaction %>% str_remove_all("[:digit:]|[:punct:]|\\+") %>% trimws()) %>% 
  spread(2, 4)

drift <-
  indtagter %>% 
  left_join(udgifter) %>% 
  gather(transaction, value, -(1:2)) %>% 
  mutate(value = value / 10^6,
         time = time %>% make_date())
  
# Plot
drift %>%
  ggplot(aes(
    x     = time,
    y     = value,
    color = transaction
  )) +
  geom_line(size = 2) +
  facet_wrap(~ sector, scales = "free") +
  theme_statgl() + 
  scale_color_statgl() +
  labs(
    title = sdg17$figs$fig1$title[language],
    subtitle = " ",
    x = " ",
    y = sdg17$figs$fig1$y_lab[language],
    color = " ",
    caption = sdg17$figs$fig1$cap[language]
  )

Statbank, revenue

Statbank, expenditure

Method


# Transform
drift <-
  indtagter %>% 
  left_join(udgifter) %>% 
  gather(transaction, value, -(1:2)) %>% 
  mutate(value = value / 10^6,
         value = round(value, 2)) %>% 
  filter(time >= year(Sys.time()) - 5) %>% 
  spread(3, 4) %>% 
  arrange(desc(time))

# Table
drift %>% 
  select(-2) %>% 
  rename(" " = 1) %>% 
  statgl_table() %>% 
  pack_rows(index = table(drift[[2]]) %>% rev()) %>% 
  add_footnote(sdg17$figs$fig1$foot[language], notation = "symbol")
Current surpluss gross saving TOTAL OUTLAYS
2022
Central government 1,28 1,28
General government sector, total 13,53 12,80
Municipalities 6,53 6,20
Selfgovernment 7,93 7,57
2021
Central government 1,39 1,39
General government sector, total 12,78 12,64
Municipalities 6,19 6,11
Selfgovernment 7,33 7,29
2020
Central government 1,36 1,36
General government sector, total 12,87 12,61
Municipalities 6,12 6,04
Selfgovernment 7,61 7,44
2019
Central government 1,38 1,38
General government sector, total 12,99 11,78
Municipalities 6,04 5,79
Selfgovernment 7,89 6,93
* Billions (DKK)



# Import 
indtagter_raw <-
  statgl_url("OFXREAI", lang = language) %>% 
  statgl_fetch(
    "sector"      = 0,
    "transaction" = 43,
    "time"        = px_all(),
    .col_code     = TRUE) %>% 
  as_tibble()

udgifter_raw <-
  statgl_url("OFXREAU", lang = language) %>% 
  statgl_fetch(
    "sector"      = 0,
    "transaction" = 44,
    "time"        = px_all(),
    .col_code     = TRUE) %>% 
  as_tibble()

bnp_raw <-
  statgl_url("NRX02", lang = language) %>% 
  statgl_fetch(
    "units"        = "L",
    "account name" = "LBNPTOT",
    "time"         = px_all(),
    .col_code      = TRUE) %>% 
  as_tibble()

# Transform
saldo <- 
  bnp_raw %>% 
  select(3, 4) %>% 
  rename("bnp" = 2) %>% 
  left_join(udgifter_raw  %>% select(3, 4) %>% rename("expenditure" = 2)) %>% 
  left_join(indtagter_raw %>% select(3, 4) %>% rename("revenue" = 2)) %>% 
  mutate(saldo = (revenue - expenditure) / bnp * 10^-3,
         time  = time %>% make_date(),
         type  = "saldo")

# Plot
saldo %>% 
  ggplot(aes(
    x    = time,
    y    = saldo,
    fill = type
  )) +
  geom_col() +
  scale_y_continuous(labels  = scales::percent_format(
    scale = 100, 
    accuracy = 1,
    big.mark = ".",
    decimal.mark = ","
    )) +
  theme_statgl() + 
  scale_fill_statgl() +
  theme(legend.position = "None") +
  labs(
    title = sdg17$figs$fig2$title[language],
    subtitle = sdg17$figs$fig2$sub[language],
    x = " ",
    y = sdg17$figs$fig2$y_lab[language],
    color = " ",
    caption = sdg17$figs$fig2$cap[language]
  )

Statbank, revenue

Statbank, expenditure

Statbank, GDP

Method, public finances


# transform
  saldo <-
  bnp_raw %>% 
  select(3, 4) %>% 
  rename("bnp" = 2) %>% 
  left_join(udgifter_raw  %>% select(3, 4) %>% rename("expenditure" = 2)) %>% 
  left_join(indtagter_raw %>% select(3, 4) %>% rename("revenue" = 2)) %>% 
  filter(time >= year(Sys.time()) - 7) %>% 
  #arrange(desc(time)) %>% 
  mutate(value = (revenue - expenditure) / bnp * 10^-3 * 100,
         value = round(value, 1),
         time  = time %>% factor(levels = unique(time)),
         saldo = sdg17$figs$fig2$saldo[language]) %>% 
  select(-(2:4)) %>% 
  spread(1, 2)



# table
saldo %>%
  rename(" " = 1) %>% 
  statgl_table() %>% 
  add_footnote(sdg17$figs$fig2$foot[language], notation = "symbol")
2017 2018 2019 2020 2021
Actual government balance 2,7 6,1 6,1 1,3 0,7
* Share of GDP

Consumer prices


GS Consumer price index
# Import
PRXPRISV_raw <-
  statgl_url("PRXPRISV", lang = language) %>% 
  statgl_fetch(
      "commodity group" = px_all(),
      "time"            = px_all(),
    .col_code           = TRUE) %>% 
  as_tibble()

# Transform
PRXPRISV <- 
  PRXPRISV_raw %>% 
  mutate(time              = time %>% as.character() %>% readr::parse_date(format = "%Y %b"),
         `commodity group` = `commodity group` %>% factor(levels = unique(`commodity group`)))

# Plot  
cpi <-
  PRXPRISV %>% 
  ggplot(aes(
    x     = time,
    y     = value,
    color = `commodity group` 
  )) +
  geom_line(size = 1) +
  theme_statgl() + 
  scale_color_statgl() +
  labs(
    title    = (statgl_url("PRXPRISV", lang = language) %>% statgl_meta())$title,
    subtitle = " ",
    x        = " ",
    y        = sdg17$figs$fig3$y_lab[language],
    color    = sdg17$figs$fig3$color[language],
    caption  = sdg17$figs$fig3$cap[language]
  )
  
plotly::ggplotly(cpi)
StatBank

Method


# Import
PRXPRISV_raw <-
  statgl_url("PRXPRISV", lang = language) %>% 
  statgl_fetch(
      "commodity group" = px_all(),
      "time"            = px_top(5),
    .col_code           = TRUE) %>% 
  as_tibble()

# Transform
PRXPRISV <-
  PRXPRISV_raw %>% 
  #arrange(desc(time)) %>% 
  mutate(time = time %>% factor(levels = unique(time)),
         `commodity group` = `commodity group` %>% factor(levels = unique(`commodity group`))) %>% 
  spread(2, 3)

# Table
PRXPRISV %>% 
  rename(" " = 1) %>% 
  statgl_table() %>% 
  row_spec(1, bold = TRUE)
2022 Jan 2022 Jul 2023 Jan 2023 Jul 2024 Jan
All goods and services 123,6 125,9 127,0 129,0 129,8
Food etc. 142,0 146,6 147,5 150,1 151,1
Bread and cereals 135,4 137,8 139,5 146,4 146,1
Meat 143,8 151,2 149,6 150,9 152,1
Fish 122,8 123,8 126,6 127,3 127,2
Milk, cream, cheese and eggs 131,5 137,6 140,4 142,2 142,0
Butter, margarine, oils and fats 178,7 190,7 205,6 205,7 211,8
Fruit 131,4 131,9 135,9 135,9 145,8
Vegetables 147,0 150,5 151,6 153,0 150,5
Sugar, jam, honey, chocolate and confectionery 171,1 171,5 176,3 178,6 180,5
Foodproducts n.e.c. 135,5 137,8 139,7 144,5 143,4
Coffee, tee and cocoa 140,4 142,3 143,5 145,0 145,6
Mineral waters, soft drinks, fruit and vegetable juices 155,3 162,7 161,2 165,7 168,1
Alcohol and tobacco 129,4 132,3 133,0 134,2 135,5
Alcohol 126,9 130,3 130,6 132,1 133,5
Tobacco 131,5 133,7 134,9 135,9 137,0
Clothing and footwear 89,6 90,4 90,6 91,3 92,2
Housing 125,5 125,9 127,7 129,4 130,1
Furnishing and household services 114,4 116,9 122,7 123,1 117,8
Medicine, pharmaceutical articles 128,3 132,0 131,5 132,8 132,5
Transportation 125,8 126,4 128,5 129,1 132,6
Telephone and postage 85,3 85,3 85,5 85,5 85,6
Leisure and culture 108,6 116,6 114,2 120,3 119,6
Restaurants and hotels 134,5 135,7 137,9 141,1 142,4
Other goods and services 117,6 117,8 119,5 121,3 123,3
# Import
PRXPRISH_raw <-
  statgl_url("PRXPRISH", lang = "da") %>%
  statgl_fetch(
      "time"  = px_all(),
      "type"  = 0,
    .col_code = TRUE) %>% 
  as_tibble()



time <- statgl_url("PRXPRISH", lang = "en") %>%
  statgl_fetch(
      "time"  = px_all()) %>% 
  select(time_eng = time)

fig_title <- unlist(statgl_meta(statgl_url("PRXPRISH", lang = language))$title %>% str_split(", "))[2]
fig_sub   <- unlist(statgl_meta(statgl_url("PRXPRISH", lang = language))$title %>% str_split(", "))[1]

# Transform
PRXPRISH <-
  PRXPRISH_raw %>% 
  cbind(time) %>% 
  mutate(time = time_eng %>% parse_date(format = "%Y %B")) %>% 
  select(-time_eng)


fig_title <- unlist(statgl_meta(statgl_url("PRXPRISH", lang = language))$title %>% str_split(", "))[2]
fig_sub   <- unlist(statgl_meta(statgl_url("PRXPRISH", lang = language))$title %>% str_split(", "))[1]

# Plot
PRXPRISH %>% 
  ggplot(aes(
    x     = time,
    y     = value,
    color = type
  )) +
  geom_line(size = 2) +
  scale_y_continuous(labels  = scales::percent_format(
    scale = 1, 
    accuracy = 1, 
    big.mark = ".",
    decimal.mark = ","
    )) +
  theme_statgl() + 
  scale_color_statgl() +
  theme(legend.position = "none") +
  labs(
    title    = fig_title,
    subtitle = fig_sub,
    x        = " ",
    y        = " ",
    caption  = sdg17$figs$fig4$cap[language]
  ) 

StatBank

Method


# Import
PRXPRISH_raw <-
  statgl_url("PRXPRISH", lang = language) %>%
  statgl_fetch(
      "time"  = px_top(5),
      "type"  = 0,
    .col_code = TRUE) %>% 
  as_tibble()

# Transform
PRXPRISH <-
  PRXPRISH_raw %>% 
  #arrange(desc(time)) %>% 
  mutate(time = time %>% factor(levels = unique(time))) %>% 
  spread(1, ncol(.))

PRXPRISH %>% 
  rename(" " = 1) %>% 
  statgl_table() %>% 
  add_footnote(fig_title, notation = "symbol")
2022 January 2022 July 2023 January 2023 July 2024 January
Rate of change from the same period the previous year 0,2 2,2 2,7 2,5 2,2
* Consumer price index

Supply balance


GS Supply balance
# Import
NRX11_raw <-
  statgl_url("NRX11", lang = language) %>% 
  statgl_fetch(
      "units"   = "K",
      "account" = px_all(),
      "time"    = px_all(),
    .col_code   = TRUE) %>% 
  as_tibble()

var <- unique(NRX11_raw[[2]])
vec <- c(var[1], var[4], var[5], var[6], var[7], var[2])

# Transform
NRX11 <-
  NRX11_raw %>% 
  filter(account %in% vec) %>% 
  mutate(account = account %>% factor(levels = unique(vec)),
         time    = time    %>% make_date()) %>% 
  arrange(account, time) %>% 
  group_by(account) %>% 
  mutate(pct = (value - lag(value)) / lag(value)) %>% 
  ungroup()

# Plot
NRX11 %>% 
  ggplot(aes(
    x     = time,
    y     = pct,
    color = account
  )) +
  geom_line(size = 2) +
  geom_hline(yintercept = 0, linetype = "dashed") + 
  facet_wrap(~ account, scales = "free") +
  scale_y_continuous(labels  = scales::percent_format(
    scale        = 100, 
    accuracy     = 1, 
    big.mark     = ".",
    decimal.mark = ","
  )) +
  theme_statgl() + 
  scale_color_statgl() +
  labs(
    title    = sdg17$figs$fig5$title[language],
    subtitle = NRX11[[1]][1],
    x        = " ",
    y        = sdg17$figs$fig5$y_lab[language],
    color    = " ",
    caption  = sdg17$figs$fig5$cap[language]
  )

StatBank


# Transform
NRX11 <-
  NRX11_raw %>% 
  filter(account %in% vec) %>% 
  mutate(account = account %>% factor(levels = unique(vec))) %>% 
  arrange(account, time) %>% 
  group_by(account) %>% 
  mutate(pct = (value - lag(value)) / lag(value) * 100,
         pct = round(pct, 1)) %>% 
  ungroup() %>% 
  #arrange(desc(time)) %>% 
  filter(time >= year(Sys.time()) - 5) %>% 
  mutate(time = time %>% factor(levels = unique(time))) %>% 
  select(-4) %>% 
  spread(3, 4)

# Table
NRX11 %>% 
  select(-1) %>% 
  rename(" " = 1) %>% 
  statgl_table() %>% 
  pack_rows(sdg17$figs$fig5$index[language], 1, length(NRX11[[2]])) %>% 
  add_footnote(NRX11[[1]][1], notation = "symbol")
2019 2020 2021
Annual percentage change
Gross Domestic Product 2,8 0,2 1,3
Private consumption 0,5 0,4 3,2
Government consumption 4,0 -1,8 1,4
Gross investment 46,9 0,4 6,5
Exports of goods and services -5,4 -5,6 0,7
Imports of goods and services 15,1 -5,8 5,9
* 2010-prices, chained values

Government consumption and block grants


GS Government consumption and block grants
# Import 
NRD11_raw <- 
  statgl_url("NRX11", lang = language) %>% 
  statgl_fetch(
    units   = "L",
    account = c("0000", "3200"),
    time    = px_all(),
    .col_code   = TRUE
  ) %>% 
  as_tibble()

OFXREAI_raw <- 
  statgl_url("OFXREAI", lang = language) %>% 
  statgl_fetch(
    sector      = c(0),
    transaction = c(27),
    time        = px_all(),
    .col_code   = TRUE
  ) %>% 
  as_tibble()

# Transform
bnp <- 
  NRD11_raw %>% 
  mutate(account = account %>% factor(levels = unique(account))) %>% 
  spread(account, value) %>% 
  left_join(OFXREAI_raw %>%
              mutate(
                transaction = transaction %>% 
                  trimws() %>% 
                  str_remove_all("[:digit:]") %>% 
                  str_remove("...") %>%
                  trimws(),
                value = value / 1000
                ) %>% 
              spread(transaction, value) %>% 
              select(-1)
            )
  
labels     <- bnp %>% colnames()
vec        <- 1:length(labels)
names(vec) <- labels

bnp_relativ <-
  bnp %>% 
  rename(
    Y = 3,
    O = 4,
    B = 5
  ) %>% 
  mutate(
    O = O / Y * 100,
    B = B / Y * 100
  ) %>% rename(vec) %>% 
  select(-3) %>% 
  gather(key, value, -units, -time) %>% 
  mutate(time = time %>% as.numeric(),
         key  = key %>% factor(levels = unique(key)))


sub_lab <- 
  bnp_relativ %>% 
  select(1) %>% 
  separate(units, c("units", "drop"), ",") %>% 
  pull(units) %>% 
  unique()


# Plot
bnp_relativ %>% 
  ggplot(aes(
    x     = time,
    y     = value,
    fill  = key
  )) +
  geom_col(size = 2) +
  facet_wrap(~ key, scales = "free", ncol = 1) +
  theme_statgl() + 
  theme(legend.position = "none") +
  scale_y_continuous(labels  = scales::percent_format(
    scale = 1
  )) +
  scale_fill_statgl() +
  labs(
    title    = sdg17$figs$fig6$title[language],
    subtitle = sub_lab,
    y        = " ",
    x        = " ",
    caption  = sdg17$figs$fig6$cap[language]
  )

StatBank


# Table
tab <- 
  bnp_relativ %>% 
  #arrange(desc(time)) %>% 
  filter(time >= year(Sys.time()) - 7) %>% 
  mutate(
    time = time %>% factor(levels = unique(time)),
    value = value %>% round(1)
    ) %>% 
  spread(time, value)

foot_lab <- 
  tab %>% 
  select(1) %>% 
  separate(units, c("units", "drop"), ",") %>% 
  pull(units) %>%
  table()

tab %>% 
  select(-1) %>% 
  rename(" " = 1) %>% 
  statgl_table() %>% 
  pack_rows(index = foot_lab) %>% 
  add_footnote(sdg17$figs$fig6$foot[language], notation = "symbol")
2017 2018 2019 2020 2021
Current prices
Government consumption 42,4 43,1 43,8 43,7 45,1
Block grants 20,0 19,9 19,3 19,4 19,4
* Share of GDP

High-speed internet


GS High-speed internet
# Import 
time  <- seq(2018, 2020)
value <- c(80, 92.6, 92.6) 
type  <- "internet"

title   <- sdg17$figs$fig7$title[language]
caption <- sdg17$figs$fig7$cap[language]
unit    <- sdg17$figs$fig7$unit[language]


# Plot
data.frame(time, value, type) %>% 
  as_tibble() %>% 
  ggplot(aes(
    x = time, 
    y = value,
    fill = type
    )) + 
  geom_col() +
  expand_limits(y = 100) +
  scale_y_continuous(labels  = scales::percent_format(
    scale        = 1,
    accuracy     = 1,
    big.mark     = ".",
    decimal.mark = ","
  )) +
  scale_fill_statgl() +
  theme_statgl() + 
  theme(legend.position = "none") +
  labs(
    title    = title,
    subtitle = unit,
    x        = " ",
    y        = " ",
    caption  = caption
  )




# Table 
value <- c("80%", "92.6%", "92.6%") 

data.frame(time, value) %>% 
  as_tibble() %>% 
  mutate(col = title) %>% 
  spread(time, value) %>% 
  rename(" " = 1) %>% 
  statgl_table()
2018 2019 2020
Access to high-speed internet 80% 92.6% 92.6%